home *** CD-ROM | disk | FTP | other *** search
/ DarkBASIC - The Ultimate 3D Game Creator / PCactive 8 CD1 - DarkBasic.iso / SOFTWARE / DEMOS / DarkForge2000 / snippets_vol4 / snip_shoot_to_kill.dba < prev    next >
Encoding:
Text File  |  2000-10-17  |  16.5 KB  |  536 lines

  1. `    -------------------------------------------------------------------------
  2. `    Shoot to Kill                            DarkForge Mini-Game (18/10/2000)
  3. `    -------------------------------------------------------------------------
  4. `    I wanted to do a complete game that didn't use any external BMP files.
  5. `    Here is the end result! Use the cursor keys or joystick and blow away the
  6. `    on-coming alien hordes. Features math based collision, smooth controls, 
  7. `    5 levels, score and great graphics in only 17k :-)
  8.  
  9. hide mouse
  10. sync rate 0
  11. sync on
  12.  
  13. `    - DF --------------------------------------------------------------------
  14. `            The GenImage function re-generates our sprites from the data
  15. `    -------------------------------------------------------------------- DF -
  16.  
  17. for a=1 to 5
  18.     GenImage(a,a)
  19. next a
  20.  
  21. `    - DF --------------------------------------------------------------------
  22. `            Make a little star for use in the background
  23. `    -------------------------------------------------------------------- DF -
  24.  
  25. cls 0 : ink rgb(200,200,200),0 : dot 1,1
  26. ink rgb(50,50,250),0 : dot 1,0 : dot 1,2 : dot 0,1 : dot 2,1
  27. get image 7,0,0,3,3 : cls 0
  28.  
  29. `    - DF --------------------------------------------------------------------
  30. `            Draw a small game logo
  31. `    -------------------------------------------------------------------- DF -
  32.  
  33. set text font "Terminal"
  34. set text size 12
  35. i=6
  36. for a=50 to 255 step 50
  37.     ink rgb(a,a,a),0
  38.     text i,0,"SHOOT TO KILL !"
  39.     dec i
  40. next a
  41. get image 8,0,0,80,16 : cls 0
  42.  
  43. set text font "Courier"
  44. set text size 10
  45.  
  46. `    - DF --------------------------------------------------------------------
  47. `            Set-up all the arrays and values used within the game
  48. `    -------------------------------------------------------------------- DF -
  49.  
  50. life=4
  51. stars=75
  52. score=0
  53. level=1
  54. px=320
  55. py=420
  56. speed=8
  57. bulletspeed=12
  58. bullethalt=timer()
  59. alienspeed#=4
  60.  
  61. dim stars(stars,3)
  62.  
  63. for i=1 to stars
  64.     stars(i,1)=rnd(639)+1
  65.     stars(i,2)=rnd(479)+1
  66.     stars(i,3)=rnd(9)+1
  67. next i
  68.  
  69. dim bullets(8,2)
  70.  
  71. for a=0 to 8
  72.  
  73.     bullets(a,1)=0
  74.     bullets(a,2)=0
  75.  
  76. next a
  77.  
  78. dim aliens#(50,4)
  79.  
  80. for a=0 to level*10
  81.  
  82.     aliens#(a,1)=rnd(620)
  83.     aliens#(a,2)=-700+rnd(400)
  84.     aliens#(a,3)=rnd(1)
  85.     aliens#(a,4)=1
  86.  
  87. next a
  88.  
  89. create bitmap 1,640,480
  90.  
  91. `    - DF Main Loop Starts Here ----------------------------------------------
  92.  
  93. do
  94.  
  95.     cls 0
  96.  
  97. `    - DF --------------------------------------------------------------------
  98. `            Check to see if we've been hit by an alien
  99. `    -------------------------------------------------------------------- DF -
  100.  
  101.     for alien=0 to level*10
  102.  
  103.         if aliens#(alien,4)=1
  104.  
  105.             alienx=int(aliens#(alien,1))+7
  106.             alieny=int(aliens#(alien,2))+7
  107.             shipx1=px-4
  108.             shipx2=px+30
  109.     
  110. `            Uncomment this to show where the collision zone is on the ship
  111. `            ink rgb(255,0,0),0
  112. `            dot shipx1,py : dot shipx2,py : dot shipx1,py+22 : dot shipx2,py+22
  113.     
  114.             if alienx>=shipx1 and alienx<=shipx2
  115.  
  116.                 if alieny>=py and alieny<=py+22
  117.     
  118. `                    We've hit one so let's reset everything
  119.     
  120.                     for a=0 to level*10
  121.                 
  122.                         aliens#(a,1)=rnd(620)
  123.                         aliens#(a,2)=-700+rnd(400)
  124.                         aliens#(a,3)=rnd(1)
  125.                         aliens#(a,4)=1
  126.                     
  127.                     next a
  128.     
  129.                     for a=0 to 8
  130.                     
  131.                         bullets(a,1)=0
  132.                         bullets(a,2)=0
  133.                     
  134.                     next a
  135.                     
  136.                     dec life
  137.  
  138.                     repeat
  139.  
  140.                         set current bitmap 0
  141.                         paste image 5,(px-20)+rnd(40),py+rnd(30)
  142.                         sync
  143.                         inc ex
  144.  
  145.                     until ex=40
  146.  
  147.                     set current bitmap 1
  148.  
  149.                     px=320
  150.                     py=420
  151.                     ex=0
  152.  
  153.                     if life=0
  154.  
  155.                         set text size 24
  156.                         set current bitmap 0
  157.  
  158.                         ink rgb(100,100,100),0
  159.                         center text 320,240,"GAME OVER"
  160.  
  161.                         ink rgb(200,200,200),0
  162.                         center text 320,239,"GAME OVER"
  163.  
  164.                         ink rgb(255,255,255),0
  165.                         center text 320,238,"GAME OVER"
  166.  
  167.                         wait key
  168.                         end
  169.  
  170.                     endif
  171.     
  172.                 endif
  173.  
  174.             endif
  175.  
  176.         endif
  177.  
  178.     next alien
  179.  
  180. `    - DF --------------------------------------------------------------------
  181. `            Test for collision between bullet and aliens
  182. `            First check the bullets, then aliens, then X and Y values
  183. `    -------------------------------------------------------------------- DF -
  184.  
  185.     for bullet=0 to 8
  186.  
  187.         if bullets(bullet,2)!0
  188.  
  189.             for alien=0 to level*10
  190.     
  191.                 if aliens#(alien,4)=1
  192.  
  193.                     bullx=bullets(bullet,1)+2
  194.                     bully=bullets(bullet,2)+3
  195.                     alienx=int(aliens#(alien,1))+7
  196.                     alieny=int(aliens#(alien,2))+7
  197.         
  198.                     if bullx>=alienx-10 and bullx<=alienx+10
  199.         
  200.                         if bully>=alieny-8 and bully<=alieny+8
  201.         
  202. `                            reset the offending bullet
  203.                             bullets(bullet,1)=0
  204.                             bullets(bullet,2)=0
  205.     
  206. `                            explode the dead alien
  207.                             aliens#(alien,4)=2
  208.  
  209.                             inc score,25
  210.  
  211.                             if score=250 then inc level
  212.                             if score=900 then inc level : inc alienspeed#,1
  213.                             if score=1500 then inc level
  214.                             if score=3500 then inc alienspeed#,1
  215.                             if score=4000 then inc level
  216.                             if score>5000 then inc alienspeed#,0.1
  217.         
  218.                         endif
  219.     
  220.                     endif
  221.     
  222.                 endif
  223.  
  224.             next alien
  225.  
  226.         endif
  227.  
  228.     next bullet
  229.  
  230. `    - DF --------------------------------------------------------------------
  231. `            Draw the starfield
  232. `    -------------------------------------------------------------------- DF -
  233.  
  234.     for i=1 to stars
  235.  
  236.         stars(i,2)=stars(i,2)+stars(i,3)
  237.         
  238.         if stars(i,2)>=480
  239.             stars(i,2)=0
  240.             stars(i,1)=rnd(640)+1
  241.         endif
  242.  
  243.         paste image 7,stars(i,1),stars(i,2)
  244.     
  245.     next i
  246.  
  247. `    - DF --------------------------------------------------------------------
  248. `            Draw your ship
  249. `    -------------------------------------------------------------------- DF -
  250.  
  251.     paste image 1,px,py
  252.  
  253. `    - DF --------------------------------------------------------------------
  254. `            Draw the aliens! Up to 50 of them depending on the level
  255. `    -------------------------------------------------------------------- DF -
  256.  
  257.     for a=0 to level*10
  258.  
  259.         alienx#=aliens#(a,1)
  260.         alieny#=aliens#(a,2)
  261.  
  262.         if aliens#(a,4)=1
  263.             paste image 2,alienx#,alieny#
  264.             inc alieny#,alienspeed#
  265.             if alieny#>=480
  266.                 alieny#=-700+rnd(400)
  267.                 alienx#=rnd(620)
  268.                 aliens#(a,1)=alienx#
  269.                 aliens#(a,2)=alieny#
  270.                 aliens#(a,3)=rnd(1)
  271.                 aliens#(a,4)=1
  272.             else
  273.                 aliens#(a,1)=alienx#
  274.                 aliens#(a,2)=alieny#
  275.             endif
  276.         else
  277.             paste image 5,alienx#,alieny#
  278.             dec alieny#,alienspeed#*2
  279.             if alieny#<=1
  280.                 alieny#=-700+rnd(400)
  281.                 alienx#=rnd(620)
  282.                 aliens#(a,1)=alienx#
  283.                 aliens#(a,2)=alieny#
  284.                 aliens#(a,3)=rnd(1)
  285.                 aliens#(a,4)=1
  286.             else
  287.                 aliens#(a,1)=alienx#
  288.                 aliens#(a,2)=alieny#
  289.             endif
  290.         endif
  291.  
  292.  
  293.     next a
  294.  
  295. `    - DF --------------------------------------------------------------------
  296. `            Check to see if there are any bullets on the move
  297. `    -------------------------------------------------------------------- DF -
  298.  
  299.     for a=0 to 8
  300.         if bullets(a,2)!0
  301.             paste image 3,bullets(a,1),bullets(a,2)
  302.         endif
  303.     next a
  304.  
  305. `    - DF --------------------------------------------------------------------
  306. `            Check the controls left or right
  307. `    -------------------------------------------------------------------- DF -
  308.  
  309.     if leftkey() or joystick left() then direction=1
  310.     if rightkey() or joystick right() then direction=2
  311.  
  312.     if direction=1
  313.         dec px,speed
  314.         if px<=0 then px=0
  315.         direction=1
  316.     endif
  317.  
  318.     if direction=2
  319.         inc px,speed
  320.         if px>=615 then px=615
  321.         direction=2
  322.     endif
  323.  
  324.     direction=0
  325.  
  326. `    - DF --------------------------------------------------------------------
  327. `            Check the fire button with timer delay to stop all bullets
  328. `            being launched in one shot!
  329. `    -------------------------------------------------------------------- DF -
  330.  
  331.     if timer()>=bullethalt+150
  332.  
  333.         if spacekey() or joystick fire a()
  334.     
  335.     `        Find a free bullet if there is one
  336.     
  337.             nextbullet=99
  338.  
  339.             for a=0 to 8
  340.     
  341.                 tempb=bullets(a,1)
  342.                 if tempb=0 then nextbullet=a
  343.     
  344.             next a
  345.  
  346.             if nextbullet!99
  347.     
  348.                 bullets(nextbullet,1)=px+11
  349.                 bullets(nextbullet,2)=py
  350.  
  351.             endif
  352.     
  353.             bullethalt=timer()
  354.     
  355.         endif
  356.  
  357.     endif
  358.  
  359. `    - DF --------------------------------------------------------------------
  360. `            Move any live bullets up the screen
  361. `    -------------------------------------------------------------------- DF -
  362.  
  363.     for a=0 to 8
  364.  
  365.         if bullets(a,2)!0
  366.  
  367.             by=bullets(a,2)
  368.             dec by,bulletspeed
  369.  
  370.             if by<=0
  371.                 bullets(a,1)=0
  372.                 bullets(a,2)=0
  373.             endif
  374.  
  375.             bullets(a,2)=by
  376.  
  377.         endif
  378.  
  379.     next a
  380.  
  381. `    - DF --------------------------------------------------------------------
  382. `            Draw the lives remaining counter
  383. `    -------------------------------------------------------------------- DF -
  384.  
  385.     for a=1 to life
  386.         paste image 4,18*a,450
  387.     next a
  388.  
  389. `    - DF --------------------------------------------------------------------
  390. `            Draw the little game logo
  391. `    -------------------------------------------------------------------- DF -
  392.  
  393.     paste image 8,640-90,0
  394.  
  395. `    - DF --------------------------------------------------------------------
  396. `            Draw the score
  397. `    -------------------------------------------------------------------- DF -
  398.  
  399.     ink rgb(155,155,155),0
  400.     text 550,449,"SCORE: "+str$(score)
  401.     ink rgb(255,255,255),0
  402.     text 550,448,"SCORE: "+str$(score)
  403.  
  404. `    - DF --------------------------------------------------------------------
  405. `            Copy the bitmap and sync the screen - nice and fast
  406. `    -------------------------------------------------------------------- DF -
  407.  
  408.     copy bitmap 1,0
  409.     sync
  410.  
  411. loop
  412.  
  413.  
  414. `    - DF Function --------------------------------------------------------
  415. `    Converts the data statements into images/sprites
  416. `    -------------------------------------------------------- DF Function -
  417.  
  418. function GenImage(n,i)
  419.  
  420.     cls 0
  421.  
  422.     if n=1 then restore ship1
  423.     if n=2 then restore alien1
  424.     if n=3 then restore bullet
  425.     if n=4 then restore lifecounter
  426.     if n=5 then restore explode
  427.  
  428.     read x
  429.     read y
  430.  
  431.     for a=0 to y
  432.         for b=0 to x
  433.             read c
  434.             ink c,0
  435.             dot b,a
  436.         next b
  437.     next a
  438.  
  439.     get image i,0,0,x,y
  440.  
  441. `    - DF Data ------------------------------------------------------------
  442. `    Sprite data starts here
  443. `    ------------------------------------------------------------ DF Data -
  444.  
  445.     ship1:
  446.     data 26
  447.     data 22
  448.     data 0,0,0,0,0,0,0,0,0,0,0,0,2113634,2113634,0,0,0,0,0,0,0,0,0,0,0,0,0
  449.     data 0,0,0,0,0,0,0,0,0,0,0,2113634,10798822,8627653,2113634,0,0,0,0,0,0,0,0,0,0,0,0
  450.     data 0,0,0,0,0,0,0,0,0,0,0,8627653,10798822,8627653,6456740,0,0,0,0,0,0,0,0,0,0,0,0
  451.     data 0,0,0,0,0,0,0,0,0,0,2113634,8627653,10798822,8627653,6456740,2113634,0,0,0,0,0,0,0,0,0,0,0
  452.     data 0,0,0,0,0,0,0,0,0,0,6456740,8627653,10798822,8627653,24832,24832,0,0,0,0,0,0,0,0,0,0,0
  453.     data 0,0,0,0,0,0,0,0,0,0,6456740,8627653,58880,42240,24832,24832,0,0,0,0,0,0,0,0,0,0,0
  454.     data 0,0,0,0,0,0,0,0,0,0,24832,42240,58880,42240,24832,24832,0,0,0,0,0,0,0,0,0,0,0
  455.     data 0,0,0,0,0,0,0,0,0,0,24832,42240,58880,42240,6456740,4284803,0,0,0,0,0,0,0,0,0,0,0
  456.     data 0,0,0,0,0,0,0,0,0,0,24832,42240,10798822,8627653,6456740,4284803,0,0,0,0,0,0,0,0,0,0,0
  457.     data 0,0,0,0,0,0,0,0,0,12969702,8627653,8627653,10798822,8627653,6456740,4284803,2113634,0,0,0,0,0,0,0,0,0,0
  458.     data 0,0,0,0,0,0,0,6456740,12969702,10798822,2113634,2113634,2113634,0,0,0,2113634,2113634,0,0,0,0,0,0,0,0,0
  459.     data 0,0,0,0,0,2113634,6456740,10798822,10798822,2113634,2113634,50918,50918,34278,34278,0,2113634,2113634,2113634,2113634,0,0,0,0,0,0,0
  460.     data 0,0,0,0,2113634,12969702,10798822,10798822,6456740,2113634,50918,50918,34278,34278,34278,16614,0,2113634,2113634,4284803,15132160,2113634,0,0,0,0,0
  461.     data 0,0,0,4284803,15132160,15132160,10798822,10798822,6456740,2113634,34278,34278,12969702,10798822,16614,16614,0,2113634,4284803,4284803,15132160,15132160,2113634,0,0,0,0
  462.     data 0,0,4284803,10798822,15132160,15132160,10798822,10798822,6456740,2113634,34278,16614,12969702,8627653,16614,16614,0,2113634,4284803,4284803,15132160,15132160,6456740,2113634,0,0,0
  463.     data 0,4284803,8627653,10798822,15132160,15115520,10798822,10798822,6456740,2113634,16614,2113634,10798822,8627653,0,16614,0,2113634,4284803,6456740,15132160,15115520,6456740,6456740,2113634,0,0
  464.     data 0,10798822,10798822,10798822,15115520,15115520,10798822,10798822,6456740,2113634,2113634,2113634,10798822,8627653,0,0,0,2113634,4284803,6456740,15115520,15115520,6456740,6456740,6456740,0,0
  465.     data 4284803,10798822,10798822,10798822,15115520,15081472,10798822,10798822,6456740,4284803,8627653,6456740,10798822,8627653,6456740,4284803,2113634,2113634,4284803,6456740,15115520,15081472,6456740,6456740,6456740,2113634,0
  466.     data 10798822,10798822,10798822,10798822,15081472,15081472,4284803,0,0,0,0,4284803,4284803,2113634,2113634,0,0,0,0,2113634,15081472,15081472,6456740,6456740,6456740,6456740,0
  467.     data 6456740,10798822,10798822,4284803,0,0,0,0,0,0,2113634,15081472,15132160,15132160,15081472,2113634,0,0,0,0,0,0,2113634,6456740,6456740,4284803,0
  468.     data 0,0,0,0,0,0,0,0,0,0,0,15081472,15115520,15115520,15081472,0,0,0,0,0,0,0,0,0,0,0,0
  469.     data 0,0,0,0,0,0,0,0,0,0,0,0,15081472,15081472,0,0,0,0,0,0,0,0,0,0,0,0,0
  470.     
  471.     alien1:
  472.     data 14
  473.     data 15
  474.     data 0,4284803,2113634,2113634,0,0,0,0,0,0,2113634,2113634,2113634,0,0
  475.     data 4284803,6456740,4284803,4284803,2113634,2113634,0,0,2113634,2113634,2113634,2113634,4284803,4284803,0
  476.     data 4284803,10798822,6456740,4284803,2113634,2113634,2113634,2113634,2113634,2113634,2113634,4284803,6456740,4284803,0
  477.     data 4284803,12969702,10798822,4284803,4284803,2113634,4284803,4284803,2113634,2113634,2113634,6456740,8627653,4284803,0
  478.     data 2113634,4284803,12969702,4284803,6456740,2113634,6456740,6456740,2113634,4284803,2113634,8627653,4284803,2113634,0
  479.     data 0,4284803,12969702,4284803,6456740,2113634,2113634,2113634,2113634,6456740,2113634,8627653,4284803,0,0
  480.     data 0,2113634,4284803,4284803,8627653,2113634,15081472,15081472,2113634,8627653,2113634,4284803,2113634,0,0
  481.     data 0,0,4284803,4284803,10798822,2113634,15115520,15081472,2113634,8627653,2113634,4284803,0,0,0
  482.     data 0,0,2113634,4284803,12969702,2113634,15115520,15115520,2113634,10798822,4284803,2113634,0,0,0
  483.     data 0,0,0,4284803,12969702,2113634,15132160,15115520,2113634,10798822,4284803,0,0,0,0
  484.     data 0,0,0,2113634,4284803,2113634,2113634,2113634,2113634,4284803,2113634,0,0,0,0
  485.     data 0,0,0,0,4284803,8627653,6456740,4284803,4284803,4284803,0,0,0,0,0
  486.     data 0,0,0,0,2113634,4284803,8627653,6456740,4284803,2113634,0,0,0,0,0
  487.     data 0,0,0,0,0,4284803,12969702,8627653,4284803,0,0,0,0,0,0
  488.     data 0,0,0,0,0,0,4284803,4284803,0,0,0,0,0,0,0
  489.     
  490.     bullet:
  491.     data 4
  492.     data 6
  493.     data 0,10798822,6456740,0,0
  494.     data 6456740,10798822,6456740,4284803,0
  495.     data 6456740,10798822,6456740,4284803,0
  496.     data 34278,50918,16614,16614,0
  497.     data 15115520,15132160,15081472,15081472,0
  498.     data 6456740,10798822,8627653,6456740,0
  499.     
  500.     lifecounter:
  501.     data 15
  502.     data 13
  503.     data 0,0,0,0,0,0,0,4284803,0,0,0,0,0,0,0,0
  504.     data 0,0,0,0,0,0,4284803,10798822,4284803,0,0,0,0,0,0,0
  505.     data 0,0,0,0,0,0,6456740,10798822,4284803,0,0,0,0,0,0,0
  506.     data 0,0,0,0,0,0,6456740,58880,24832,0,0,0,0,0,0,0
  507.     data 0,0,0,0,0,4284803,42240,58880,6456740,2113634,0,0,0,0,0,0
  508.     data 0,0,0,0,4284803,8627653,6456740,10798822,6456740,4284803,0,0,0,0,0,0
  509.     data 0,0,0,2113634,10798822,10798822,4284803,4284803,4284803,6456740,4284803,2113634,0,0,0,0
  510.     data 0,0,2113634,15132160,10798822,4284803,50918,34278,34278,2113634,6456740,15132160,0,0,0,0
  511.     data 0,2113634,10798822,15115520,10798822,4284803,34278,12969702,16614,2113634,6456740,15115520,6456740,2113634,0,0
  512.     data 2113634,10798822,10798822,15115520,10798822,4284803,16614,10798822,16614,2113634,6456740,15115520,8627653,8627653,0,0
  513.     data 6456740,10798822,10798822,15081472,10798822,4284803,4284803,6456740,4284803,4284803,6456740,15081472,8627653,8627653,4284803,0
  514.     data 6456740,6456740,0,2113634,4284803,0,15115520,15132160,15115520,0,4284803,0,0,4284803,2113634,0
  515.     data 0,0,0,0,0,0,0,15081472,0,0,0,0,0,0,0,0
  516.  
  517.     explode:
  518.     data 13
  519.     data 13
  520.     data 0,0,0,0,0,0,0,0,0,0,0,15081472,15115520,0
  521.     data 0,15115520,15081472,0,0,0,0,0,0,15081472,15115520,15132160,15081472,0
  522.     data 0,15081472,15132160,15115520,0,15081472,15081472,15081472,15115520,15132160,15132160,15115520,0,0
  523.     data 0,0,15115520,15132160,15132160,15115520,15132160,15132160,15132160,15132160,15132160,15081472,0,0
  524.     data 0,0,0,15132160,15132160,15132160,15132160,15132160,15132160,15132160,15115520,0,0,0
  525.     data 0,0,15081472,15115520,15132160,15132160,12969702,15132160,15132160,15132160,15081472,0,0,0
  526.     data 0,0,15081472,15132160,15132160,12969702,12969702,12969702,15132160,15132160,15081472,0,0,0
  527.     data 0,0,15081472,15115520,15132160,15132160,12969702,15132160,15132160,15115520,15081472,0,0,0
  528.     data 0,0,15115520,15132160,15132160,15132160,15132160,15132160,15132160,15132160,0,0,0,0
  529.     data 0,15081472,15132160,15132160,15132160,15115520,15132160,15115520,15132160,15132160,15115520,0,0,0
  530.     data 0,15115520,15132160,15132160,15115520,15081472,15081472,15081472,0,15115520,15132160,15081472,0,0
  531.     data 15081472,15132160,15115520,15081472,15081472,15081472,0,0,0,0,15081472,15115520,0,0
  532.     data 15115520,15081472,0,0,0,0,0,0,0,0,0,0,0,0
  533.  
  534. endfunction
  535.  
  536.